﻿@{
    Layout = null;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
      "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
  <head>  
      <script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
      <link href="../../Scripts/Test/qunit.css" rel="stylesheet" type="text/css" />
      <script src="../../Scripts/Test/qunit.js" type="text/javascript"></script>
    <script src="http://code.jquery.com/jquery-latest.js"> </script>  
    <script type="text/javascript" src="../../Scripts/Site/TypeControlers.js"></script>
      <script src="../../Scripts/Site/globalScripts.js" type="text/javascript"></script>
      @{Html.RenderPartial("_ConfigScripts");}
    <script src="/content/layout.c.js"> </script>  
      
      <script type="text/javascript">



          $(document).ready(function ()
          {

              module("type controlers");

              test("test T_String", function ()
              {
                  var str = new T_String().getControls("f1", "f2", 44, "class", "cfn");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "f2")).length, 1, 'Expected 1 as the result, result was: ' + el.filter(stringFormat("[name='{0}.FieldName']", "f2")).length);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "f2")).length, 1, 'Expected 1 as the result, result was: ' + el.filter(stringFormat("#{0}\\.FieldName", "f2")).length);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "f2")).val(), "f1", 'Expected f1 as the result, result was: ' + el.filter(stringFormat("#{0}\\.FieldName", "f2")).val());

                  equals(el.find(stringFormat("[name='{0}.{1}']", "f2", "cfn")).length, 1, 'Expected 1 as the result, result was: ' + el.filter(stringFormat("[name='{0}.{1}']", "f2", "cfn")).length);
                  equals(el.find(stringFormat("#{0}\\.{1}", "f2", "cfn")).length, 1, 'Expected 1 as the result, result was: ' + el.filter(stringFormat("#{0}\\.{1}", "f2", "cfn")).length);
                  equals(el.find(stringFormat("#{0}\\.{1}", "f2", "cfn")).val(), 44, 'Expected f1 as the result, result was: ' + el.filter(stringFormat("#{0}\\.{1}", "f2", "cfn")).val());
              });



              test("test T_Boolean", function ()
              {
                  var str = new T_Boolean().getControls("field", "formName", "val", "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Boolean")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Boolean")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Boolean")).val(), "true");
              });

              test("test T_Integer", function ()
              {
                  var str = new T_Integer().getControls("field", "formName", "val", "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Integer")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Integer")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Integer")).val(), "val");
              });


              test("test T_Long", function ()
              {
                  var str = new T_Long().getControls("field", "formName", "val", "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Integer")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Integer")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Integer")).val(), "val");
              });

              test("test T_Double", function ()
              {
                  var str = new T_Double().getControls("field", "formName", "val", "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Double")).length, 1);
                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Double")).hasClass('Numeric'), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).val(), "val");
              });

              test("test T_Date", function ()
              {
                  var str = new T_Date().getControls("field", "formName", "Date('12213213", "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");


                  var value = new Date(12213213).stringify();
                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Date")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).hasClass("class"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).hasClass("Date"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).val(), value);
              });


              test("test T_DateTime", function ()
              {
                  var str = new T_DateTime().getControls("field", "formName", "Date('12213213", "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");


                  var value = new Date(12213213).stringify();
                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Date")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).hasClass("class"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).hasClass("Date"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Date")).val(), value);
              });

              test("test T_Duration", function ()
              {
                  var str = new T_Duration().getControls("field", "formName", { Value: 4.555, Unit: 2 }, "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Double")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).hasClass("class"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).hasClass("Numeric"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).val(), 4.56);

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Unit")).length, 1);
                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Unit")).val(), 2);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Unit")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Unit")).hasClass("class"), 1);

              });


              test("test T_Money", function ()
              {
                  var str = new T_Money().getControls("field", "formName", { Value: 4.555, Unit: 2 }, "class");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Double")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).hasClass("class"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).hasClass("Numeric"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Double")).val(), 4.56);

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Currency")).length, 1);
                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "Currency")).val(), 2);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Currency")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Currency")).hasClass("class"), 1);

              });

              test("test T_Entity", function ()
              {
                  var str = new T_Entity().getControls("field", "formName", { Id: { Value: "333"} }, "class", null, "tn");
                  var el = $("<div>").append(str);
                  equals(el.find(stringFormat("[name='{0}.FieldName']", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.FieldName", "formName")).val(), "field");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "TypeName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "TypeName")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "TypeName")).val(), "tn");

                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "ID")).length, 1);
                  equals(el.find(stringFormat("[name='{0}.{1}']", "formName", "ID")).val(), "333");
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Value")).length, 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Value")).hasClass("EntitySearch"), 1);
                  equals(el.find(stringFormat("#{0}\\.{1}", "formName", "Value")).hasClass("class"), 1);

              });


              module("global scripts");

              test("is number", function ()
              {
                  equals(isNumber("4.55"), true);
                  equals(isNumber("d"), false);
                  equals(isNumber("44hh"), false);
                  equals(isNumber("4. 55"), false);
              });

              test("round", function ()
              {
                  equals(round(4.3, 0), 4);
                  equals(round(4.3, 1), 4.3);
                  equals(round(4.35555, 3), 4.356);

              });

              test("stringFormat", function ()
              {
                  equals(stringFormat("333 {0} {1} {0}4234", 4, 5), "333 4 5 44234");
              });

              test("stringFormat", function ()
              {
                  equals(stringFormat("333 {0} {1} {0}4234", 4, 5), "333 4 5 44234");
              });

              test("stringify", function ()
              {
                  var date = new Date();
                  equals(date.stringify(), stringFormat("{0}/{1}/{2}", date.getFullYear(), date.getMonth() + 1, date.getDate()));
              });

              test("addDays", function ()
              {
                  var date = new Date();
                  equals(date.addDays(2).addDays(2).addDays(2).stringify(), date.addDays(6).stringify());
              });

              test("show_loading", function ()
              {
                  var div = $("<div>");
                  div.show_loading(true);
                  equals(div.find('.coverDiv').length, 1);
                  div.show_loading(false);
                  equals(div.find('.coverDiv').length, 0);
              });

              module("clarizen grid");
              test("Column", function ()
              {
                  var col = new Column({
                      name: "Name",
                      displayName: "Project Name",
                      getData: function (item)
                      {
                          return "111";
                      },
                      getHiddenData: function ()
                      {
                          return [{ name: "offset", val: "dd" }, { name: "offset2", val: "dd"}];
                      }
                  });
                  equals(col.getName(), "Project Name");
                  equals(col.getData(), "111");
                  equals(col.getHiddenData()[0].name, "offset");
              });

              test("clarizen table", function ()
              {
                  var col = new Column({
                      name: "Name",
                      displayName: "Project Name",
                      getData: function (item)
                      {
                          return "111";
                      },
                      getHiddenData: function ()
                      {
                          return [{ name: "offset", val: "dd" }, { name: "offset2", val: "dd"}];
                      }
                  });
                  var div = $("<div>");
                  div.clarizen_table({
                      cols: [col],
                      width: 100,
                      height: 160,
                      headerHeight: 30,
                      elements: [{ Name: "name"}]
                  });

                  var h = div.find('.Header');
                  
                  var c = div.find('.DataTableContainer');
                  var t = c.find('.DataTable');

                  equals(h.length, 1);
                  equals(h.find('th').html(), "Project Name");
                  equals(h.height(), 30);
                  equals(h.width(), 100);
                  
                  equals(c.length, 1);
                  equals(t.length, 1);
                  equals(c.width(), 120);
                  equals(t.width(), 100);
                  equals(t.find('td').html(), "111");
              });

              module("tsedit");

              
          });  
    </script>  
  </head>  
  <body>  
    <h1 id="qunit-header">QUnit example</h1>  
    <h2 id="qunit-banner"></h2>  
    <h2 id="qunit-userAgent"></h2>  
    <ol id="qunit-tests">  
    </ol>  
  </body>  
</html>